<?
header("Content-Type:text/html;charset=utf-8");
include_once 'include/include.php';
c_create::createClass('admin');
$admin = new admin();
if ($_SESSION["Mflevel"]>1)
{
	echo '<SCRIPT language=javascript>
				alert("您的用户权限不允许使用此功能！");
				window.location.href="javascript:history.back()";
			 </script>';
	exit;
}
if (trim($_POST['CgMadminid'])>0)
{
	//print_r($_POST);
	//exit;
	//修改管理用户
	if (($_POST['Mpassword'] <> $_POST['Mpassword2']) and (isset($_POST['Mpassword'])) and trim($_POST['Mpassword'])<>"")
	{
		echo '<SCRIPT language=javascript>
			alert("错误，修改用户信息前后两次输入的密码不一致！");
			window.location.href="javascript:history.back()";
			</script>';
		exit;
	}
	if (($_POST['Mflevel'] >1) and count($_POST['Mcompetence'])<1)
	{
		echo '<SCRIPT language=javascript>
			alert("请为普通管理员赋予至少一个的正确操作权限！");
			window.location.href="javascript:history.back()";
			</script>';
		exit;
	}
	unset($_POST['adduser']);
	unset($_POST['Mpassword2']);
	$_POST['Madminid']=$_POST['CgMadminid'];
	unset($_POST['CgMadminid']);
	if ( isset($_POST['Mpassword']) and (trim($_POST['Mpassword'])<>""))
	{
		$_POST['Mpassword']=md5($_POST['Mpassword']);
	}
	else{
		unset($_POST['Mpassword']);
	}
	//print_r($_POST);
	//exit;
	if ($admin->addRecord($_POST)>0)
	{
		echo '<SCRIPT language=javascript>
			alert("成功修改管理员信息！");
			window.location.href="./Manage_edit.php";
		 </script>';
		exit;
	}
	else{
		echo '<SCRIPT language=javascript>
			alert("修改管理员信息出错，请稍后再试！");
			window.location.href="./Manage_edit.php";
		 </script>';
	}
}
if (trim($_GET['id'])>0)
{
	//修改管理用户
	$getuserinfo = $admin->getOneAdminInfo($_GET['id']);
	$getuserMcompetence = $getuserinfo['Mcompetence'];
}
$outvar[headline] = '管理员信息编辑';
$sidebarmenu=$Adminlinkitem;
assignMore($getuserinfo);
$outvar[userMcompetence] = $getuserMcompetence;
$updatedate=(date("Y")+2)."-".date("m")."-".date("d");
$outvar['sidebarmenu']=$sidebarmenu;
outFile("manageadd");
?>